
#include <string.h>
#include "stdio.h"
#include "lvgl.h"
#include "lvgl_example.h"
#include "lv_linux_fbdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

static const char *getenv_default(const char *name, const char *dflt)
{
    return getenv(name) ?: dflt;
}

#if LV_USE_LINUX_FBDEV
void lv_linux_disp_init(void)
{
    const char *device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
    lv_display_t *disp = lv_linux_fbdev_create();
    lv_linux_fbdev_set_file(disp, device);
}
#endif

int main(void)
{

    printf("\r\napp [LVGL9.2.0] run. compiled_time %s %s\r\n", __DATE__, __TIME__);

    lv_init();
    printf("lvgl_init\r\n");
    lv_linux_disp_init();
    printf("fb disp_init\r\n");
    fflush(stdout);
    lv_example_button();
    while (1)
    {
        lv_tick_inc(5);
        lv_task_handler();
        usleep(5000);
        //    uint32_t idle_time;

        // /*Handle LVGL tasks*/
        // while(1) {

        //     idle_time = lv_timer_handler(); /*Returns the time to the next timer execution*/
        //     usleep(idle_time * 1000);
        //      lv_tick_inc(5);
        // }
    }
}
